package com.dd.ma;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.*;

public class Matest extends TimerTask {

	public static void main(String arg[]) {

		ScheduledExecutorService service = Executors
				.newScheduledThreadPool(100);
		ScheduledFuture future1=service.scheduleWithFixedDelay(new Matest(),1,5,TimeUnit.SECONDS);
		try {
			Thread.sleep(10000);
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			System.out.println("stop at:"+df.format(new Date()));
			future1.cancel(true);
			service.shutdown();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public void run() {
		try {
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			System.out.println("run at:"+df.format(new Date()));
			//Thread.sleep(3000);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
